package cn.yunhe.service;

import cn.yunhe.dao.DistrictDao;
import cn.yunhe.pojo.District;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DistrictService {
    SqlSession session=null;
    DistrictDao districtDao =null;

    /**
     * 初始化
     */
    public void initial(){
        session=SqlSessionFactoryUtil.getSqlSession();
        districtDao=session.getMapper(DistrictDao.class);
    }

    /**
     * 销毁
     */
    public void destory(){
        if (session!=null){
            session.commit();
            session.close();
        }
    }

    /**
     * 插入
     * @param district
     * @return
     */
    public boolean insertDistrict(District district){
        initial();
        boolean flag= districtDao.insertDistrict(district);
        destory();
        return flag;
    }

    /**
     * 查询
     * @param district
     * @return
     */
    public List<District> districtList(District district){
        initial();
        List<District> districtList=districtDao.districtList(district);
        destory();
        return districtList;
    }


}
